#import "dfhgwhruebvhrheyadmitultimate.h"
#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "dfhgwhruebvhrheybeforehandversionViewController.h"
#import "dfhgwhruebvhrheyreciprocaltransportViewController.h"
#import "dfhgwhruebvhrheyvetobulletinViewController.h"
@interface dfhgwhruebvhrheybeforehandversionViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *storeBtn;
@property (weak, nonatomic) IBOutlet UIButton *onLineBtn;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollIV;
@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (nonatomic, strong) dispatch_group_t group;
@property (nonatomic, strong) dfhgwhruebvhrheyreciprocaltransportViewController *codeVC;
@property (nonatomic, strong) dfhgwhruebvhrheyvetobulletinViewController *barCodeVC;
@end
@implementation dfhgwhruebvhrheybeforehandversionViewController
- (dfhgwhruebvhrheyreciprocaltransportViewController *)codeVC {
	if (_codeVC == nil) {
		_codeVC = (dfhgwhruebvhrheyreciprocaltransportViewController *)[UIStoryboard storyboard:@"Home" withidentifier:@"repayment_code"];
	}
	return _codeVC;
}
- (dfhgwhruebvhrheyvetobulletinViewController *)barCodeVC {
	if (_barCodeVC == nil) {
		_barCodeVC = (dfhgwhruebvhrheyvetobulletinViewController *)[UIStoryboard storyboard:@"Home" withidentifier:@"repayment_bar_code"];
	}
	return _barCodeVC;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadUI];
	[self loadData];
}
- (void)loadUI {
	[self configBackIcon:@"dhgfywegwygeydwcurvereciprocal"];
	self.navigationItem.title = @"Repayment";
	[self configRightIcon:@"navigation_right"];
	self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
	self.codeVC.type = self.type;
	self.codeVC.repayment = self.repayment;
	self.codeVC.coupon_id = self.coupon_id;
	self.codeVC.amountString = self.amountString;
	[self addChildViewController:self.codeVC];
	self.barCodeVC.type = self.type;
	self.barCodeVC.repayment = self.repayment;
	self.barCodeVC.coupon_id = self.coupon_id;
	self.barCodeVC.amountString = self.amountString;
	[self addChildViewController:self.barCodeVC];
	[self.containerView addSubview:self.codeVC.view];
	[self.containerView addSubview:self.barCodeVC.view];
}
- (void)loadData {
	__weak typeof(self) weakSelf = self;
	if (self.group == nil) {
		self.group = dispatch_group_create();
	}
	dispatch_group_enter(self.group);
	[self.codeVC getRepaymentCode:^(dfhgwhruebvhrheyengineeringroyal * _Nonnull code) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_group_leave(strongSelf.group);
		[strongSelf.barCodeVC bindCodeData:code];
	}];
	dispatch_group_enter(self.group);
	[self.barCodeVC getRepaymentBarCode:^{
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_group_leave(strongSelf.group);
	}];
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	dispatch_group_notify(self.group, dispatch_get_main_queue(), ^{
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
	});
}
- (void)loadHomeData:(void(^)(dfhgwhruebvhrheyadmitultimate *statusModel))callback {
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwlambbreast path:homeApi isEncrypt:NO withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		dfhgwhruebvhrheyadmitultimate *homeModel = [dfhgwhruebvhrheyadmitultimate yy_modelWithJSON:json];
		if (callback) {
			callback(homeModel);
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		NSLog(@"==== %@", error);
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
	}];
}
- (void)backAction {
	[self loadHomeData:^(dfhgwhruebvhrheyadmitultimate *statusModel) {
		if(statusModel.status != 5) {
			[self.navigationController popToRootViewControllerAnimated:YES];
		}else {
			[self.navigationController popViewControllerAnimated:YES];
		}
	}];
}
- (IBAction)repaymentToggleAction:(UIButton *)sender {
	switch (sender.tag) {
		case 100: {
			[self .scrollIV setContentOffset:CGPointMake(0, 0)];
		}
			break;
		case 200: {
			[self .scrollIV setContentOffset:CGPointMake(dhgfywegwygeydwdispositionvisualize, 0)];
		}
			break;
		default:
			break;
	}
}
- (void)viewDidLayoutSubviews {
	[super viewDidLayoutSubviews];
	[self.codeVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.left.bottom.equalTo(self.containerView);
		make.width.mas_equalTo(dhgfywegwygeydwdispositionvisualize);
	}];
	[self.barCodeVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.right.bottom.equalTo(self.containerView);
		make.left.equalTo(self.codeVC.view.mas_right);
		make.width.equalTo(self.codeVC.view);
	}];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
	self.storeBtn.selected = NO;
	self.onLineBtn.selected = NO;
	self.storeBtn.titleLabel.font = [UIFont regular:15];
	self.onLineBtn.titleLabel.font = [UIFont regular:15];
	if (scrollView.contentOffset.x == 0) {
		self.onLineBtn.selected = YES;
		self.onLineBtn.titleLabel.font = [UIFont semiBold:15];
	}else {
		self.storeBtn.selected = YES;
		self.storeBtn.titleLabel.font = [UIFont semiBold:15];
	}
}
@end
